import { Catch, HttpStatus } from '@midwayjs/core'
import { Context } from '@midwayjs/koa'
import { MidwayValidationError } from '@midwayjs/validate'

@Catch(MidwayValidationError)
export class ValidateErrorFilter {
  async catch(err: MidwayValidationError, ctx: Context) {
    const status = HttpStatus.UNPROCESSABLE_ENTITY

    ctx.status = status

    return {
      status,
      message: `校验参数错误: ${err.message}`
    }
  }
}
